﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
//----------//
using System.Data.SqlClient;
using System.Data;
using System.Configuration;
using System.Globalization;
using System.IO;
using System.Web;
using System.Windows.Forms;
//---------------------------------//
namespace QLKTX1._0.DB
{
    class ConnectDB
    {
        private SqlConnection conn;      
       
        public ConnectDB()
        {          
            conn = new SqlConnection(IConnectionType.strConnMSSQL_none);
            conn.Open();
            conn.Close();
        }       

        // get Connection

        public SqlConnection getConnection()
        {
            return this.conn;
        }

        // co che phi ket noi
        public DataTable getDataTable(string strQuery)
        {
            DataTable dt = new DataTable();

            SqlDataAdapter da = new SqlDataAdapter(strQuery, conn);
           
            da.Fill(dt);

            return dt;
        }
        // co che co ket noi
        public bool executeQuery(string strQuery)
        {
            int num = 0;

            SqlCommand cmd = new SqlCommand();

            if (conn.State == ConnectionState.Closed)
            {
                conn.Open();
            }

            cmd.Connection = conn;

            cmd.CommandText = strQuery;

            cmd.CommandType = CommandType.Text;

            num = cmd.ExecuteNonQuery();

            if (conn.State == ConnectionState.Open)
            {
                conn.Close();
            }

            if (num > 0)
            {
                return true;
            }

            return false;
        }
    }
}
